// pages/order/order.js
var app = getApp();
var that;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDate:"选择日期",
    orderTime:"选择时间",
    customerName:"",
    customerTel:"",
    itemId:"",
    staffId:"",
    storeId:"",
    value:"0",
    selectStaffList:[],
  },

  getDate(e){
    this.setData({orderDate:e.detail.value});
  },

  getTime(e){
    this.setData({orderTime:e.detail.value});
  },

  getName(e){
    this.setData({customerName:e.detail.value});
  },

  getTel(e){
    this.setData({customerTel:e.detail.value});
  },
  
  getStaff(e){
    this.setData({value:e.detail.value})
     this.setData({staffId:this.data.selectStaffList[e.detail.value].staffId})
  },

  confirm(){
    console.log(that.data);
    wx.request({
      url: 'http://192.168.1.173:8080/api/order/add.do',
      data: JSON.stringify(that.data),
      dataType: "json",
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      method: "post",
      success: (result) => {
        wx.showToast({
          title: '预约成功',
        })
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    this.setData({itemId:options.itemId})
    this.setData({storeId:options.storeId})
    this.setData({customerName:app.globalData.userInfo.nickName})
    wx.request({
      url: 'http://192.168.1.173:8080/api/staff/selectStaffList.do',
      data: {storeId:options.storeId},
      dataType: "json",
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      method: "get",
      success: (result) => {
        that.setData({selectStaffList:result.data.data})
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})